#include "Shop.h"
#include "StoneTowerShopItem.h"



Shop::Shop(void)
{

}


Shop::~Shop(void)
{

}


void Shop::setPlayer(Player * player)
{
	pl = player;
	stat.gold = pl->getGold();
	stat.level = pl->getLevel();

}

void Shop::observeeChange()
{
	if(pl->getGold() != stat.gold && pl->getLevel())
	{
		stat.gold = pl->getGold();
		stat.level = pl->getLevel();

		for(it = subElements.begin();it != subElements.end();++it)
		{
			ShopItem * shopItem = (ShopItem*)(*it);
			shopItem->updateState(stat);
		}
	}
}

void Shop::init()
{
	container = new Container();
	layoutX = 0;
	layoutY = 0;
	container->setPosition(714,0);
	container->setWidth(86);
	container->setHeight(400);
	container->setBGColor(0,0,0,255);



}

void Shop::addShopItem(ShopItem * item)
{
	Widget * widget = item->getWidget();
	widget->setPosition(layoutX,layoutY);
	layoutX += widget->getWidth();
	if(layoutX > container->getWidth())
	{
		layoutY += widget->getHeight();
	}

	addElement(item);
}
void Shop::removeShopItem(ShopItem * item)
{
	removeElement(item);
}

void Shop::deleteShopItem(ShopItem * item)
{
	deleteElement(item);
}
void Shop::onDestroy()
{

}